let http = require('../../../utils/api.js');
import {
    toData,
    myHttps
} from '../../../utils/util.js';
import {
    indexTime
} from '../../../utils/indexTime.js';
Page({

    data: {
        hiddenLoading: false,
        items: [], //所有收藏
        startX: 0, //开始坐标
        startY: 0,
        userId: '',//用户id
        size: 10,//页容量
        current: 1,//页码
        length:'',//收藏的数量
        title: '创始人仍受雇于FB',//假数据
        titles: ' WhatsApp创始人仍受雇于FB，未放 弃数亿美元股，票Whats 今年4月联合创始人宣布将从将facebook 旗下的这家',
        nick:'',//我的名字
        avatar:'',//我的头像
    },

    onLoad: function (e) {
        this.mycollect(e.userId, this.data.size, this.data.current)
        this.setData({
            userId: e.userId
        })
        var that = this;
        //common是自己写的公共JS方法，可忽略
        //common.sys_main(app, that, e);
        this.setData({
            items: this.data.items
        });
        this.GetInfo();//用户详情

    },
    // 获取用户信息接口 
    GetInfo() {
        var url = http.api.userInfo + this.data.userId;
        myHttps({
            url: url,
            method: "GET",
        }).then(res => {
            if (res.code == 1) {
                // console.log(res.data)
                this.setData({
                    nick: res.data.nick_name,
                    avatar: res.data.avatar
                })
            }
        }).catch(err => { })
    },
    // 点击文章 跳转到文章
    goDetails(e) {
        let id = e.currentTarget.dataset.id
        // console.log(id)
        wx.navigateTo({
            url: '../../details/details?id=' + id,
            success: function (res) { },
            fail: function (res) { },
            complete: function (res) { },
        })
    },
    // 点击解读 去解读详情
    gounscrambleDetails(e) {
        let id = e.currentTarget.dataset.id
        // console.log(id)
        wx.navigateTo({
            url: '../../unscrambleDetails/unscrambleDetails?id=' + id,
            success: function (res) { },
            fail: function (res) { },
            complete: function (res) { },
        })
    },
    // 获取解读列表接口
    mycollect(id, size, page) {
        this.setData({
            hiddenLoading: false
        })
        let url = http.api.reviewList + id + '/reviews?size=' + size + '&page=' + page;
        myHttps({
            url: url,
            method: "GET",
        }).then(res => {
            // console.log(res)
            if (res.code == 1) {
                for (var i = 0; i < res.data.content.length; i++) {
                    res.data.content[i].update_time = indexTime(res.data.content[i].update_time)
                    this.data.items.push(res.data.content[i])
                }
                this.setData({
                    items: this.data.items,
                    hiddenLoading: true,
                    length: this.data.items.length
                })
                // wx.setNavigationBarTitle({
                //     title: '收藏（' + this.data.length + '）' //页面标题为路由参数
                // })
            }
        }).catch(err => { })
    },
    //下拉刷新从新初始化页码,条数
    onPullDownRefresh: function () {
        this.setData({
            hiddenLoading: false
        })
        //下拉三个点消失
        wx.stopPullDownRefresh();
        this.setData({
            items: [],
            size: 10,
            current: 1,
            hiddenLoading: false
        })
        this.mycollect(this.data.userId, this.data.size, this.data.current);
    },
    // 上拉加载五条数据
    onReachBottom: function () {
        this.setData({
            size: 10,
            current: this.data.current + 1,
            hiddenLoading: false
        })
        this.mycollect(this.data.userId, this.data.size, this.data.current);
    },
})